package com.dragon.app.concurrent;

/**
 * 
 * <p>class: DeadLockTest</p>  
 * <p>Description: 测试死锁</p>  
 * @author SmallDragon
 * @date 2019年5月7日
 *
 */
public class DeadLockTest {

	static class MyThread implements Runnable {
		private String lock1;
		private String lock2;

		public MyThread() {
			super();
		}

		public MyThread(String lock1, String lock2) {
			super();
			this.lock1 = lock1;
			this.lock2 = lock2;
		}

		@Override
		public void run() {
			synchronized (lock1) {
				System.out.println(Thread.currentThread().getName() + "获取到：" + lock1 + "，准备获取：" + lock2);
				synchronized (lock2) {
					System.out.println(Thread.currentThread().getName() + "获取到：" + lock2);
				}
			}
		}
	}

	public static void main(String[] args) {
		String LockA = "LockA";
		String LockB = "LockB";

		new Thread(new MyThread(LockA, LockB)).start();
		new Thread(new MyThread(LockB, LockA)).start();

	}

}
